/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    fragment_base_light.h
 * Desc:    Mesh base light shader
 * Version: 1.03
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES
	
	#ifndef FRAGMENT_BASE_LIGHT
		#define FRAGMENT_BASE_LIGHT
		
		uniform sampler2D s_texture_0;
		uniform sampler2D s_texture_1;
		uniform sampler2D s_texture_2;
		uniform sampler2D s_texture_3;
		
		uniform half4 detail_transform;
		
	#else
		
		#include <core/shaders/simple/mesh/fragment_base_sample.h>
		
		half3 camera_direction = s_texcoord_2.xyz;
		
		#ifdef WORLD
			fixed3 light_direction = s_texcoord_1.xyz;
			fixed3 color = getDiffuse(s_material_shading,diffuse.xyz,normal,light_direction);
			color += getSpecularNormalize(s_material_shading,specular.xyz,normal,light_direction,camera_direction);
		#else
			half4 light_direction = s_texcoord_1;
			fixed3 color = getDiffuseSpecularNormalizeAttenuate(s_material_shading,diffuse.xyz,specular.xyz,normal,light_direction,camera_direction);
		#endif
		
	#endif
	
/******************************************************************************\
*
* Direct3D11/Direct3D119
*
\******************************************************************************/

#elif DIRECT3D11 || DIRECT3D119
	
	#ifndef FRAGMENT_BASE_LIGHT
		#define FRAGMENT_BASE_LIGHT
		
		Texture2D s_texture_0 : register(t0);
		Texture2D s_texture_1 : register(t1);
		Texture2D s_texture_2 : register(t2);
		Texture2D s_texture_3 : register(t3);
		
		cbuffer shader_parameters {
			#ifdef OVERLAY_0 || OVERLAY_1 || MULTIPLY_0 || MULTIPLY_1
				float4 detail_transform;
			#endif
		};
		
	#else
		
		#include <core/shaders/simple/mesh/fragment_base_sample.h>
		
		half3 camera_direction = IN.texcoord_2.xyz;
		
		#ifdef WORLD
			half3 light_direction = IN.texcoord_1.xyz;
			half3 color = getDiffuse(s_material_shading,diffuse.xyz,normal,light_direction);
			color += getSpecularNormalize(s_material_shading,specular.xyz,normal,light_direction,camera_direction);
		#else
			half4 light_direction = IN.texcoord_1;
			half3 color = getDiffuseSpecularNormalizeAttenuate(s_material_shading,diffuse.xyz,specular.xyz,normal,light_direction,camera_direction);
		#endif
		
	#endif
	
#endif
